package eu.fritschi.parachatcapture;

import java.util.concurrent.BlockingQueue;

import org.apache.log4j.Logger;

public class ParachatMessageProcessor extends Thread {
	private static final Logger logger = Logger.getLogger(ParachatMessageProcessor.class);
	
	private final BlockingQueue<ParachatMessage> messageQueue;
	private final GoogleTranslateTextToSpeech googleTranslateTextToSpeech = new GoogleTranslateTextToSpeech();
	
	public ParachatMessageProcessor(BlockingQueue<ParachatMessage> messageQueue) {
		this.messageQueue = messageQueue;
	}
	
	@Override
	public void run() {
		logger.info("Started.");
		try {
			while (!isInterrupted()) {
				ParachatMessage parachatMessage = messageQueue.take();
				googleTranslateTextToSpeech.speakMessage(parachatMessage);
			}
		} catch (InterruptedException e) {
			logger.info("Interrupted.");
		} finally {
			logger.info("Terminated.");
		}
	}
}